package com.qf.front.biz;

import com.qf.ym.entity.UserEntity;
import com.qf.ym.mapper.UserMapper;
import com.qf.ym.pojo.UserPojo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;
    @Override
    public UserEntity login(UserEntity ue) {
        UserPojo up = userMapper.login(ue);
        System.out.println(up);
        UserEntity userEntity = pojoToEntity(up);
        return userEntity;
    }

    @Override
    public boolean regist(UserEntity ue) {

        return userMapper.regist(ue);
    }

    @Override
    public UserEntity equalsaName(UserEntity ue) {
        UserPojo up=userMapper.equalsaName(ue);
        UserEntity ue1 = pojoToEntity(up);
        return ue1;
    }

    //entity转换pojo
    public UserPojo entityToPojo(UserEntity ue){
        if(ue==null){
            return null;
        }
        UserPojo up = new UserPojo();
        up.setAname(ue.getAname());
        up.setApass(ue.getApass());
        up.setAacount(ue.getAacount());
        up.setAid(ue.getAid());
        up.setAstatus(ue.getAstatus());
        up.setAemail(ue.getAemail());
        up.setAimage(ue.getAimage());
        up.setAphone(ue.getAphone());

        return up;
    }
    public UserEntity pojoToEntity(UserPojo up){
        if(up==null){
            return null;
        }
        UserEntity ue = new UserEntity();
        ue.setAname(up.getAname());
        ue.setApass(up.getApass());
        ue.setAacount(up.getAacount());
        ue.setAid(up.getAid());
        ue.setAstatus(up.getAstatus());
        ue.setAemail(up.getAemail());
        ue.setAimage(up.getAimage());
        ue.setAphone(up.getAphone());

        return ue;
    }

}
